﻿using System.Collections.Generic;

namespace KBEngine.Setting.TypeDef
{
    public interface IType
    {
        string TypeName { get; }
    }
    public class BaseType : IType
    {
        string m_typeName;
        public BaseType(string typeName)
        {
            m_typeName = typeName;
        }
        public string TypeName
        {
            get { return m_typeName; }
            set { m_typeName = value; }
        }
        public override string ToString()
        {
            return TypeName;
        }
    }
    public class AliasType : BaseType
    {
        IType m_realType = null;
        public AliasType(string aliasName, IType realType)
            : base(aliasName)
        {
            m_realType = realType;
        }

        public IType RealType
        {
            get { return m_realType; }
            set { m_realType = value; }
        }
        public override string ToString()
        {
            return $"{TypeName} from {m_realType.TypeName}";
        }
    }
    public class UserType : BaseType
    {
        public class Field
        {
            public string FieldName;
            public IType Type;
            public bool persistent = true;   //kbe默认为true
            public uint? databaseLength = null;
        }

        /// <summary>
        /// 由点(.)分割;前部为脚本(module)名称,后部为实列化名称(浅规则:大写为PICKLER结构类型,小写为PICKLER结构类型实列化)
        /// 如:
        /// 1.AVATAR_DATA.AVATAR_DATA_PICKLER 代表脚本AVATAR_DATA.py中存在AVATAR_DATA_PICKLER类型定义
        /// 2.AVATAR_INFOS.avatar_info_inst   代表脚本AVATAR_INFOS.py中存在类型为AVATAR_INFOS_PICKLER的avatar_info_inst实列
        /// </summary>
        public string ImplementedBy;
        public List<Field> Properties = new List<Field>();
        public UserType(string userTypeName) : base(userTypeName)
        {
        }
    }
    public class ArrayType : IType
    {
        public static readonly string ArrayTyteStr = "Array...";
        IType m_elementType = null;

        public ArrayType(IType type)
        {
            m_elementType = type;
        }
        public string TypeName => ArrayTyteStr;
        public IType ElementType
        {
            get { return m_elementType; }
            set { m_elementType = value; }
        }
        public override string ToString()
        {
            return m_elementType.TypeName;
        }
    }
}
